//
//  HMStatusBottomView.swift
//  CZBKWB31
//
//  Created by Linkon Y on 16/8/13.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
//底部
class HMStatusBottomView: UIView {
    
    var retweetBtn: UIButton?
    var commentBtn: UIButton?
    var unlikeBtn: UIButton?
    
    var statusViewModel: HMStatusViewModel?{
        didSet{
        
            retweetBtn?.setTitle(statusViewModel?.repostsCountStr, forState: UIControlState.Normal)
            commentBtn?.setTitle(statusViewModel?.commentsCountStr, forState: UIControlState.Normal)
            unlikeBtn?.setTitle(statusViewModel?.attitudesCountStr, forState: UIControlState.Normal)
        
        
        
        }
    }
    

    override init(frame: CGRect) {
        super.init(frame:frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
     // MARK: - 设置视图
   private func setupUI(){
        backgroundColor = UIColor.whiteColor()
    
    //添加控件
    retweetBtn = addChildBtn("timeline_icon_retweet", title: "转发")
    commentBtn = addChildBtn("timeline_icon_comment", title: "评论")
    unlikeBtn = addChildBtn("timeline_icon_unlike", title: "赞")
    let line1 = addChildLine()
    let line2 = addChildLine()
    //添加约束
    retweetBtn!.snp_makeConstraints { (make) in
        make.leading.top.bottom.equalTo(self)
        //新特性宽 等于下一个 自动平分
        make.width.equalTo(commentBtn!)
    }
    commentBtn!.snp_makeConstraints { (make) in
        make.leading.equalTo(retweetBtn!.snp_trailing)
        make.top.bottom.equalTo(self)
        make.width.equalTo(unlikeBtn!)
    }
    unlikeBtn!.snp_makeConstraints { (make) in
        make.leading.equalTo(commentBtn!.snp_trailing)
        make.top.trailing.bottom.equalTo(self)
    }
    line1.snp_makeConstraints { (make) in
        make.centerY.equalTo(self)
        make.centerX.equalTo(retweetBtn!.snp_trailing)
        
    }
    line2.snp_makeConstraints { (make) in
        make.centerY.equalTo(self)
        make.centerX.equalTo(commentBtn!.snp_trailing)
    }
    
    }
    /**
     - parameter imageName: 图片名
     - parameter title:     按钮名
     
     - returns: 返回btn
     */
    func addChildBtn(imageName:String , title: String) -> UIButton{
        let button = UIButton()
        //背景图片
        button.setBackgroundImage(UIImage(named:"timeline_card_bottom_background"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named:"timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        //设置image
        button.setImage(UIImage(named:imageName), forState: UIControlState.Normal)
        button.setTitle(title, forState: UIControlState.Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        //增加btn
        addSubview(button)
        return button
    }
 
    func addChildLine() -> UIImageView{
       let img = UIImageView(imageName:"timeline_card_bottom_line")
        addSubview(img)
        return img
    }
}

